#!/user/bin/python3
# @Author:  LSY
# @Date:    2020/11/8
from app.models.bo.hanfan.hanfan_model_input_bo import HanFanModelInputBO
from app.services.models.base_model import BaseModel
from app.services.models.pickle_model import PickleModel
from flask import current_app
import pandas as pd
import numpy as np
from app.utils.constant import HanFanStatus


class LuzhaRModel(BaseModel):

    def __init__(self):
        super().__init__(model_name="luzha_r_model")

    def process(self, input):
        try:
            b1 = input.get("CG_LT_GL_GL04_Zha_R", 0)
            b2 = input.get("CG_LT_GL_GL04_LDWDBTE1138_D_Wai6693", 0)
            b3 = input.get("CG_LT_GL_GL04_Zha_Al2O3", 0)
            b4 = input.get("CG_LT_GL_GL04_Zha_SiO2", 0)
            b5 = input.get("CG_LT_GL_GL04_Zha_Mg_Al", 0)
            b6 = input.get("CG_LT_GL_GL04_LDWDBTE1113_D_Wai5963", 0)
            b7 = input.get("CG_LT_GL_GL04_LDWDBTE1110_DB_Wai5963", 0)
            b8 = input.get("CG_LT_GL_GL04_LDWDBTE1135_DB_Wai6693", 0)
            b9 = input.get("CG_LT_GL_GL04_LDWDBTE1117_DN_Wai5963", 0)
            b10 = input.get("CG_LT_GL_GL04_Zha_CaO", 0)
            b11 = input.get("CG_LT_GL_GL04_LDWDBTE1103_DB_5160", 0)
            b12 = input.get("CG_LT_GL_GL04_LDWDBTE1107_B_Wai5963", 0)
            b13 = input.get("CG_LT_GL_GL04_Tie_Cr", 0)
            b14 = input.get("CG_LT_GL_GL04_LDWDBTE1108_B_Zhong5963", 0)

            y_R = 0.775 + b1 * 0.043 - b2 * 0.00001 + b3 * 0.001 - b4 * 0.022 + b5 * 0.131 + b6 * 0.000047 - b7 * 0.0011 + b8 * 0.001 - b9 * 0.001 + b10 * 0.026 - b11 * 0.001 + b12 * 0.001 + b13 * 0.309 + b14 * 0.0000249
            return y_R
        except Exception as e:
            current_app.logger.info(e, exc_info=1)


class LuzhaTiO2Model(BaseModel):

    def __init__(self):
        super().__init__(model_name="luzha_tio2_model")

    def process(self, input):
        try:
            c1 = input.get("CG_LT_GL_GL04_Zha_TiO2", 0)
            c2 = input.get("CG_LT_GL_GL04_Zha_V2O5", 0)
            c3 = input.get("CG_LT_GL_GL04_LDWDBTE1115_D_Nei5963", 0)
            c4 = input.get("CG_LT_GL_GL04_LDWDBTE1119_DN_Nei5963", 0)
            c5 = input.get("CG_LT_GL_GL04_LDWDBTE1112_DB_Nei5963", 0)
            c6 = input.get("CG_LT_GL_GL04_LDWDBTE1109_B_Nei5963", 0)
            c7 = input.get("CG_LT_GL_GL04_LDWDBTE1121_N_Zhong5963", 0)
            c8 = input.get("CG_LT_GL_GL04_LDWDBTE1102_Zhong_5160", 0)
            c9 = input.get("CG_LT_GL_GL04_LDWDBTE1111_DB_Zhong5963", 0)
            c10 = input.get("CG_LT_GL_GL04_LDWDBTE1141_Zhong_Zhongxin6693", 0)
            c11 = input.get("CG_LT_GL_GL04_LDWDBTE1137_DB_Nei6693", 0)
            c12 = input.get("CG_LT_GL_GL04_LDWDBTE1140_D_Nei6693", 0)
            c13 = input.get("CG_LT_GL_GL04_LDWDBTE1130_XB_Zhong5963", 0)
            c14 = input.get("CG_LT_GL_GL04_LDWDBTE1134_B_Nei6693", 0)
            c15 = input.get("CG_LT_GL_GL04_LDWDBTE1136_DB_Zhong6693", 0)
            c16 = input.get("CG_LT_GL_GL04_LDWDBTE1117_DN_Wai5963", 0)
            c17 = input.get("CG_LT_GL_GL04_LDWDBTE1139_D_Zhong6693", 0)
            c18 = input.get("CG_LT_GL_GL04_LDWDBTE1125_XN_Nei5963", 0)
            y_TiO2 = 3.251 + c1 * 0.842 - c2 * 0.052 + c3 * 0.006 + c4 * 0.01 + c5 * 0.012 + c6 * 0.004 + c7 * 0.006 + c8 * 0.005 - c9 * 0.034 - c10 * 0.059 - c11 * 0.032 + c12 * 0.078 - c13 * 0.0002 \
                     + c14 * 0.012 + c15 * 0.029 + c16 * 0.01 - c17 * 0.018 - c18 * 0.008
            return y_TiO2

        except Exception as e:
            current_app.logger.info(e, exc_info=1)

class LuzhaMgAlModel(BaseModel):

    def __init__(self):
        super().__init__(model_name="luzha_mg_al_model")

    def process(self, input):
        try:
            d1 = input.get("input.CG_LT_GL_GL04_Zha_Mg_Al", 0)
            d2 = input.get("input.CG_LT_GL_GL04_Zha_MgO", 0)
            d3 = input.get("input.CG_LT_GL_GL04_Zha_R", 0)
            d4 = input.get("input.CG_LT_GL_GL04_Zha_TiO2", 0)
            d5 = input.get("input.CG_LT_GL_GL04_LDWDBTE1138_D_Wai6693", 0)
            d6 = input.get("input.CG_LT_GL_GL04_LDWDBTE1129_XB_Wai5963", 0)
            d7 = input.get("input.CG_LT_GL_GL04_LDWDBTE1120_N_Wai5963", 0)
            d8 = input.get("input.CG_LT_GL_GL04_LDWDBTE1128_X_Nei5963", 0)
            d9 = input.get("input.CG_LT_GL_GL04_LDWDBTE1135_DB_Wai6693", 0)
            d10 = input.get("input.CG_LT_GL_GL04_LDWDBTE1125_XN_Nei5963", 0)
            d11 = input.get("input.CG_LT_GL_GL04_LDWDBTE1154_XB_Wai6693", 0)
            d12 = input.get("input.CG_LT_GL_GL04_LDWDBTE1133_B_Zhong6693", 0)

            y_Mg_Al = 0.122 + d1 * 1.054 - d2 * 0.007 - d3 * 0.074 - d4 * 0.02 + d5 * 0.000012 - d6 * 0.001 + d7 * 0.0000033 + d8 * 0.001 + d9 * 0.000012 - d10 * 0.00002 - d11 * 0.0000031 - d12 * 0.000045
            return y_Mg_Al
        except Exception as e:
            current_app.logger.info(e, exc_info=1)


luzha_r_model = LuzhaRModel()
luzha_tio2_model = LuzhaTiO2Model()
luzha_mg_al_model = LuzhaMgAlModel()
